package homeWork;

public class instrument {
    public static void main(String[] args) {
        Musician musician = new Musician();

        Instrument erhu = new Erhu();
        musician.play(erhu);  // 乐手弹奏二胡

        Instrument piano = new Piano();
        musician.play(piano);  // 乐手弹奏钢琴

        Instrument violin = new Violin();
        musician.play(violin);  // 乐手弹奏小提琴
    }

}


// 乐器类 Instrument
class Instrument {
    public void makeSound() {
        // 空实现，需要在子类中重写
    }
}

// 二胡类 Erhu
class Erhu extends Instrument {
    @Override
    public void makeSound() {
        System.out.println("Erhu sound");
    }
}

// 钢琴类 Piano
class Piano extends Instrument {
    @Override
    public void makeSound() {
        System.out.println("Piano sound");
    }
}

// 小提琴类 Violin
class Violin extends Instrument {
    @Override
    public void makeSound() {
        System.out.println("Violin sound");
    }
}

// 乐手类 Musician
class Musician {
    public void play(Instrument instrument) {
        instrument.makeSound();
    }
}
